package com.GamersCom.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GameDAO
{
	protected QueryMgr qm = new QueryMgr();
	
	public void insert(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public void delete(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public void update(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public List<Game> getAll(String query) throws SQLException
	{
		ResultSet rs = qm.fetchList(query);
		List<Game> gameList = new ArrayList<Game>();
		
		if ( ! rs.isBeforeFirst() )
		{
			return null;
		}
		
		while (rs.next())
		{
			Game game = new Game();
			game.setId(rs.getInt("id"));
			game.setName(rs.getString("name"));
			game.setCompany(rs.getString("company"));
			game.setSummary(rs.getString("summary"));
			game.setWebsite(rs.getString("website"));
			game.setReleaseDate(rs.getDate("releaseDate"));
			game.setPlatform(rs.getString("platform"));
			game.setGenre(rs.getString("genre"));
			gameList.add(game);
		}
		
		return gameList;
	}
	
	
}
